#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct student
{
    int age;
    char name[10];
    int height;
    int weight;
}Stu;

void age_Sort(Stu* x)
{
  for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5-i-1; j++)
        {
            Stu M;
            if (x[i].age<x[i+1].age)
            {
                Stu M = x[i];
                x[i] = x[i+1];
                x[i+1] = M;
            }
        }
    }
}


int main(int argc, char const *argv[])
{
    //下面这个是在栈上的数据
    Stu A = {22,"张三",168,66};
    Stu B = {28,"李四",172,57};
    Stu C = {13,"王五",164,82};
    Stu D = {19,"赵六",183,76};
    Stu E = {17,"文七",176,69};

    Stu age_Sort_B2L[5] ={A,B,C,D,E};
    age_Sort(age_Sort_B2L); 
    printf("按照从大到小的年龄排序,他们的顺序为:\n");
    for (int i = 0; i < 5; i++)
    {
        printf("%s,%d岁\n",age_Sort_B2L[i].name,age_Sort_B2L[i].age);
    }
    
  





    //printf("A学生的年龄是%d岁,姓名叫%s,身高为%dcm,体重为%dkg\n",A.age,A.name,A.height,A.weight);

    //下面是写在堆上的数据，如下所知，很麻烦，所以暂不使用
    /*Stu *B =(Stu*)malloc(sizeof(Stu));
    B->age = 16;
    B->height = 162;
    strcpy(B->name,"陈百");
    B->weight = 63;
    B->phone.memory = 64;
    strcpy(B->phone.model,"vivox66");
    printf("B学生的年龄是%d岁,姓名叫%s,身高为%dcm,体重为%dkg,他的手机是%s,他手机的内存大小为%dG\n",B->age,B->name,B->height,B->weight,B->phone.model,B->phone.memory);
    */
    return 0;
}
